<!--题库试题展示组件-->
<template>
	<div>
		<!--大题题干-->
		<template v-if="question.questionstemDetail && question.questionstemDetail.questionstemId">
			<qb-show-combination :question="questionInfo" />
		</template>
		<!-- 独立题型 -->
		<template v-else-if="question.questionstemDetail">
			<qb-show-basic :question="questionInfo" />
		</template>
		<!-- 大题下小题 -->
		<template v-else>
			<qb-show-basic :question="questionInfo" />
		</template>
	</div>
</template>

<script>
    import QbShowBasic from './qb-show-basic.vue';
    import QbShowCombination  from './qb-show-combination.vue';
	export default {
        name:'qb-show',
		props: {
			question: {
                type:Object,
                default:()=>{}
            },
		},
        components:{
            QbShowBasic,
            QbShowCombination
        },
		data() {
			return {
				questionInfo: {},
                typeList:{
                    S: "【单选题】",
                    M: "【多选题】",
                    J: "【判断题】",
                    F: "【填空题】",
                    O: "【简答题】",
                    I: "【不定项选择】",
                    BC: "【选词填空】",
                    CF:"【完形填空】",
                    L:"【听力题】",
                    A:"【材料分析】",
                    C:"【配伍题】",
				}
			};
		},
		watch: {
            question: {
				deep: true,
				immediate: true,
				handler(newV) {
					let  question = JSON.parse(JSON.stringify(newV));
                    if(question.questionstemDetail && question.questionstemDetail.questionstemId){//大题
                        question = { ...question, ...question.questionstemDetail };
                        delete question.questionstemDetail;
                        let questionstemContent = JSON.parse(question.questionstemContent);
                        question.questionstemContentTitle = questionstemContent.title;
                        question.questionstemContentOption = questionstemContent.option;
                        question.questionTypeName = this.typeList[question.questionstemType];
                    } else if(question.questionstemDetail){//普通题型
                        question = question.questionList[0];
                        question = { ...question, ...question.questionDetail };
                        delete question.questionDetail;
                        question.questionTypeName = this.typeList[question.questionType];
						this.questionInfo =  question;
                    } else {//大题下小题
                        question = { ...question, ...question.questionDetail };
						delete question.questionDetail;
                        question.questionTypeName = this.typeList[question.questionType];
						this.questionInfo =  question;
                    }
                    this.questionInfo = question;

				}
			}
		}
	};
</script>
